package org.acra;

import android.app.Application;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageInfo;
import android.os.Process;
import android.text.format.Time;
import android.util.Log;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.acra.sender.HttpSender;

public class ErrorReporter
  implements Thread.UncaughtExceptionHandler
{
  private static boolean j = true;
  private boolean a = false;
  private final Context b;
  private final SharedPreferences c;
  private final List d = new ArrayList();
  private final org.acra.b.d e;
  private final i f = new i();
  private final Thread.UncaughtExceptionHandler g;
  private Thread h;
  private Throwable i;

  ErrorReporter(Context paramContext, SharedPreferences paramSharedPreferences, boolean paramBoolean)
  {
    this.b = paramContext;
    this.c = paramSharedPreferences;
    this.a = paramBoolean;
    String str = org.acra.b.b.a(this.b);
    Time localTime = new Time();
    localTime.setToNow();
    this.e = new org.acra.b.d(this.b, paramSharedPreferences, localTime, str);
    this.g = Thread.getDefaultUncaughtExceptionHandler();
    Thread.setDefaultUncaughtExceptionHandler(this);
    c();
  }

  private String a(org.acra.b.c paramc)
  {
    Time localTime = new Time();
    localTime.setToNow();
    long l = localTime.toMillis(false);
    String str1 = paramc.a(ReportField.IS_SILENT);
    StringBuilder localStringBuilder = new StringBuilder().append("").append(l);
    if (str1 != null);
    for (String str2 = e.a; ; str2 = "")
      return str2 + ".stacktrace";
  }

  private String a(String[] paramArrayOfString)
  {
    if ((paramArrayOfString != null) && (paramArrayOfString.length > 0))
    {
      for (int k = -1 + paramArrayOfString.length; k >= 0; k--)
        if (!this.f.a(paramArrayOfString[k]))
          return paramArrayOfString[k];
      return paramArrayOfString[(-1 + paramArrayOfString.length)];
    }
    return null;
  }

  private void a(String paramString, org.acra.b.c paramc)
  {
    try
    {
      Log.d(ACRA.LOG_TAG, "Writing crash report file " + paramString + ".");
      new l(this.b).a(paramc, paramString);
      return;
    }
    catch (Exception localException)
    {
      Log.e(ACRA.LOG_TAG, "An error occurred while writing the report file...", localException);
    }
  }

  private void a(Throwable paramThrowable, ReportingInteractionMode paramReportingInteractionMode, boolean paramBoolean1, boolean paramBoolean2)
  {
    boolean bool1 = true;
    if (!this.a)
      return;
    boolean bool2;
    if (paramReportingInteractionMode == null)
    {
      paramReportingInteractionMode = ACRA.getConfig().q();
      bool2 = false;
    }
    while (true)
    {
      if (paramThrowable == null)
        paramThrowable = new Exception("Report requested by developer");
      boolean bool3;
      label73: String str;
      aa localaa;
      if ((paramReportingInteractionMode == ReportingInteractionMode.TOAST) || ((ACRA.getConfig().B() != 0) && ((paramReportingInteractionMode == ReportingInteractionMode.NOTIFICATION) || (paramReportingInteractionMode == ReportingInteractionMode.DIALOG))))
      {
        bool3 = bool1;
        if (bool3)
          new m(this).start();
        org.acra.b.c localc = this.e.a(paramThrowable, paramBoolean1, this.h);
        str = a(localc);
        a(str, localc);
        if ((paramReportingInteractionMode != ReportingInteractionMode.SILENT) && (paramReportingInteractionMode != ReportingInteractionMode.TOAST) && (!this.c.getBoolean("acra.alwaysaccept", false)))
          break label262;
        Log.d(ACRA.LOG_TAG, "About to start ReportSenderWorker from #handleException");
        localaa = a(bool2, bool1);
        label168: if (bool3)
        {
          j = false;
          new n(this).start();
        }
        if ((paramReportingInteractionMode != ReportingInteractionMode.DIALOG) || (this.c.getBoolean("acra.alwaysaccept", false)))
          break label297;
      }
      while (true)
      {
        new o(this, localaa, bool1, str, paramBoolean2).start();
        return;
        if ((paramReportingInteractionMode != ReportingInteractionMode.SILENT) || (ACRA.getConfig().q() == ReportingInteractionMode.SILENT))
          break label303;
        bool2 = bool1;
        break;
        bool3 = false;
        break label73;
        label262: ReportingInteractionMode localReportingInteractionMode = ReportingInteractionMode.NOTIFICATION;
        localaa = null;
        if (paramReportingInteractionMode != localReportingInteractionMode)
          break label168;
        Log.d(ACRA.LOG_TAG, "About to send status bar notification from #handleException");
        b(str);
        localaa = null;
        break label168;
        label297: bool1 = false;
      }
      label303: bool2 = false;
    }
  }

  private void a(boolean paramBoolean1, boolean paramBoolean2, int paramInt)
  {
    String[] arrayOfString = new j(this.b).a();
    Arrays.sort(arrayOfString);
    if (arrayOfString != null)
      for (int k = 0; k < arrayOfString.length - paramInt; k++)
      {
        String str = arrayOfString[k];
        boolean bool = this.f.b(str);
        if (((bool) && (paramBoolean1)) || ((!bool) && (paramBoolean2)))
        {
          File localFile = new File(this.b.getFilesDir(), str);
          if (!localFile.delete())
            Log.e(ACRA.LOG_TAG, "Could not delete report : " + localFile);
        }
      }
  }

  private void b(String paramString)
  {
    NotificationManager localNotificationManager = (NotificationManager)this.b.getSystemService("notification");
    c localc = ACRA.getConfig();
    Notification localNotification = new Notification(localc.x(), this.b.getText(localc.z()), System.currentTimeMillis());
    CharSequence localCharSequence1 = this.b.getText(localc.A());
    CharSequence localCharSequence2 = this.b.getText(localc.y());
    Intent localIntent = new Intent(this.b, CrashReportDialog.class);
    Log.d(ACRA.LOG_TAG, "Creating Notification for " + paramString);
    localIntent.putExtra("REPORT_FILE_NAME", paramString);
    PendingIntent localPendingIntent = PendingIntent.getActivity(this.b, 0, localIntent, 134217728);
    localNotification.setLatestEventInfo(this.b, localCharSequence1, localCharSequence2, localPendingIntent);
    localNotificationManager.cancelAll();
    localNotificationManager.notify(666, localNotification);
  }

  private boolean b(String[] paramArrayOfString)
  {
    int k = paramArrayOfString.length;
    for (int m = 0; m < k; m++)
    {
      String str = paramArrayOfString[m];
      if (!this.f.b(str))
        return false;
    }
    return true;
  }

  private void f()
  {
    if ((ACRA.getConfig().q() == ReportingInteractionMode.SILENT) || ((ACRA.getConfig().q() == ReportingInteractionMode.TOAST) && (ACRA.getConfig().h())))
    {
      this.g.uncaughtException(this.h, this.i);
      return;
    }
    Log.e(ACRA.LOG_TAG, this.b.getPackageName() + " fatal error : " + this.i.getMessage(), this.i);
    Process.killProcess(Process.myPid());
    System.exit(10);
  }

  aa a(boolean paramBoolean1, boolean paramBoolean2)
  {
    aa localaa = new aa(this.b, this.d, paramBoolean1, paramBoolean2);
    localaa.start();
    return localaa;
  }

  public void a()
  {
    this.d.clear();
  }

  void a(String paramString)
  {
    Log.d(ACRA.LOG_TAG, "Creating Dialog for " + paramString);
    Intent localIntent = new Intent(this.b, CrashReportDialog.class);
    localIntent.putExtra("REPORT_FILE_NAME", paramString);
    localIntent.setFlags(268435456);
    this.b.startActivity(localIntent);
  }

  public void a(Throwable paramThrowable)
  {
    a(paramThrowable, ACRA.getConfig().q(), false, false);
  }

  public void a(org.acra.sender.d paramd)
  {
    this.d.add(paramd);
  }

  public void a(boolean paramBoolean)
  {
    String str1 = ACRA.LOG_TAG;
    StringBuilder localStringBuilder = new StringBuilder().append("ACRA is ");
    if (paramBoolean);
    for (String str2 = "enabled"; ; str2 = "disabled")
    {
      Log.i(str1, str2 + " for " + this.b.getPackageName());
      this.a = paramBoolean;
      return;
    }
  }

  @Deprecated
  public void addCustomData(String paramString1, String paramString2)
  {
    this.e.a(paramString1, paramString2);
  }

  void b()
  {
    a(true, true, 0);
  }

  public void b(org.acra.sender.d paramd)
  {
    a();
    a(paramd);
  }

  void b(boolean paramBoolean)
  {
    if (paramBoolean);
    for (int k = 1; ; k = 0)
    {
      a(false, true, k);
      return;
    }
  }

  public void c()
  {
    long l = this.c.getInt("acra.lastVersionNr", 0);
    PackageInfo localPackageInfo = new org.acra.d.j(this.b).a();
    int k;
    String[] arrayOfString2;
    if ((localPackageInfo != null) && (localPackageInfo.versionCode > l))
    {
      k = 1;
      if (k != 0)
      {
        if (ACRA.getConfig().f())
          b();
        SharedPreferences.Editor localEditor = this.c.edit();
        localEditor.putInt("acra.lastVersionNr", localPackageInfo.versionCode);
        localEditor.commit();
      }
      if (((ACRA.getConfig().q() == ReportingInteractionMode.NOTIFICATION) || (ACRA.getConfig().q() == ReportingInteractionMode.DIALOG)) && (ACRA.getConfig().e()))
        b(true);
      j localj = new j(this.b);
      String[] arrayOfString1 = localj.a();
      if ((arrayOfString1 != null) && (arrayOfString1.length > 0))
      {
        ReportingInteractionMode localReportingInteractionMode = ACRA.getConfig().q();
        arrayOfString2 = localj.a();
        boolean bool = b(arrayOfString2);
        if ((localReportingInteractionMode != ReportingInteractionMode.SILENT) && (localReportingInteractionMode != ReportingInteractionMode.TOAST) && ((!bool) || ((localReportingInteractionMode != ReportingInteractionMode.NOTIFICATION) && (localReportingInteractionMode != ReportingInteractionMode.DIALOG))))
          break label279;
        if ((localReportingInteractionMode == ReportingInteractionMode.TOAST) && (!bool))
          org.acra.d.l.a(this.b, ACRA.getConfig().B(), 1);
        Log.v(ACRA.LOG_TAG, "About to start ReportSenderWorker from #checkReportOnApplicationStart");
        a(false, false);
      }
    }
    label279: 
    do
    {
      return;
      k = 0;
      break;
      if (ACRA.getConfig().q() == ReportingInteractionMode.NOTIFICATION)
      {
        b(a(arrayOfString2));
        return;
      }
    }
    while (ACRA.getConfig().q() != ReportingInteractionMode.DIALOG);
    a(a(arrayOfString2));
  }

  public void d()
  {
    c localc = ACRA.getConfig();
    Application localApplication = ACRA.getApplication();
    a();
    if (!"".equals(localc.o()))
    {
      Log.w(ACRA.LOG_TAG, localApplication.getPackageName() + " reports will be sent by email (if accepted by user).");
      b(new org.acra.sender.a(localApplication));
    }
    do
    {
      return;
      if (!new org.acra.d.j(localApplication).a("android.permission.INTERNET"))
      {
        Log.e(ACRA.LOG_TAG, localApplication.getPackageName() + " should be granted permission " + "android.permission.INTERNET" + " if you want your crash reports to be sent. If you don't want to add this permission to your application you can also enable sending reports by email. If this is your will then provide your email address in @ReportsCrashes(mailTo=\"your.account@domain.com\"");
        return;
      }
      if ((localc.j() != null) && (!"".equals(localc.j())))
      {
        b(new HttpSender(ACRA.getConfig().N(), ACRA.getConfig().O(), null));
        return;
      }
    }
    while ((localc.i() == null) || ("".equals(localc.i().trim())));
    a(new org.acra.sender.b());
  }

  public void handleSilentException(Throwable paramThrowable)
  {
    if (this.a)
    {
      a(paramThrowable, ReportingInteractionMode.SILENT, true, false);
      Log.d(ACRA.LOG_TAG, "ACRA sent Silent report.");
      return;
    }
    Log.d(ACRA.LOG_TAG, "ACRA is disabled. Silent report not sent.");
  }

  public void uncaughtException(Thread paramThread, Throwable paramThrowable)
  {
    try
    {
      if (!this.a)
      {
        if (this.g != null)
        {
          Log.e(ACRA.LOG_TAG, "ACRA is disabled for " + this.b.getPackageName() + " - forwarding uncaught Exception on to default ExceptionHandler");
          this.g.uncaughtException(paramThread, paramThrowable);
          return;
        }
        Log.e(ACRA.LOG_TAG, "ACRA is disabled for " + this.b.getPackageName() + " - no default ExceptionHandler");
        return;
      }
    }
    catch (Throwable localThrowable)
    {
      if (this.g != null)
      {
        this.g.uncaughtException(paramThread, paramThrowable);
        return;
        this.h = paramThread;
        this.i = paramThrowable;
        Log.e(ACRA.LOG_TAG, "ACRA caught a " + paramThrowable.getClass().getSimpleName() + " exception for " + this.b.getPackageName() + ". Building report.");
        a(paramThrowable, ACRA.getConfig().q(), false, true);
      }
    }
  }
}

/* Location:           D:\Studium\Bachelorarbeit\BA Marcus Wobig\BA\BA\Decompiler\PicturePassword APK\Programm\PicturePassword_dex2jar.jar
 * Qualified Name:     org.acra.ErrorReporter
 * JD-Core Version:    0.6.2
 */